package cn.bb.bbstudy.config;

import cn.bb.bbstudy.pojo.Invite;
import cn.bb.bbstudy.service.InviteService;
import cn.bb.bbstudy.utils.BBUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Random;

@Component
public class CrontabTask {
    @Autowired
    private InviteService inviteService;

    @Async
    @Scheduled(cron = "0 0 0 * * ?")
    public void insert() {
        Invite invite = new Invite();
        invite.setCode(new Random().nextInt(10000) + "");
        invite.setGmtCreate(BBUtils.getTime());
        inviteService.insertSelective(invite);
        System.out.println("插入邀请码!!!!!!!");
    }
}
